Java Class Example

您所在的位置:网站首页 java code examples of Java Class Example

Java Class Example

2023-03-14 08:06| 来源: 网络整理| 查看: 265

Im not sure if you still need this answered, but ill answer it for others who might see this in the future date.

You cannot directly alter other class’s variable when it is set as private, so if you create an class object in the main class, and have to set the name, you can’t just do objName.name = “name”. you need to call the setName function like objName.setName(“name”);, as setName function itself is set public so anything outside of its scope can use the function freely. This is necessary when you don’t want name variable accessible freely, where many things can go wrong if you do. imagine if you have class with variables that require accurate information, but the variables are not set private and something accessed it by accident, altering it.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3